package de.zainodis.authorlist.model.parsing;

import java.io.IOException;
import java.util.Collection;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import de.zainodis.authorlist.core.Application;
import de.zainodis.authorlist.model.AuthorLibraryComponent;

public class AuthorParser extends XmlFeedParser<String> {

   protected static final String ENTRY_ELEMENT = "string";

   @Override
   public void handleStartTag(String name, XmlPullParser parser) throws XmlPullParserException,
	    IOException {
	 if (ENTRY_ELEMENT.equals(name)) {
	    String author = parser.nextText();
	    if (author != null) {
		  addItem(author);
	    }
	 }
   }

   @Override
   public void handleEndTag(String name, XmlPullParser parser) throws XmlPullParserException,
	    IOException {
	 // Not needed
   }

   @Override
   public void processParsedElements(Collection<String> items) {
	 AuthorLibraryComponent component = Application.getComponent(AuthorLibraryComponent.class);
	 component.addAuthors(items);
   }

}
